package tools.blast;

public class LongBlastHit2blastM8alignmentGenerator {

	public static blastM8Alignment LongBlastHit2blastM8alignment(String s){
		blastM8Alignment ba=new blastM8Alignment();
		String[] tmp=s.split("\n");
		for(int i=0;i<tmp.length;i++){
			if(tmp[i].startsWith(" Score =")){
				//read header
				ba.score=Double.parseDouble(tmp[i].split("bits")[0].substring(8).trim());
				ba.e_value=Double.parseDouble(tmp[i].split("Expect")[1].split("=")[1].trim());
				ba.alignment_length=Integer.parseInt(tmp[i+1].split("/")[1].split(" ")[0]);
				ba.gap_openings=Integer.parseInt(tmp[i+1].split("/")[2].split("=")[1].trim());
				ba.identity=Double.parseDouble(tmp[i+1].split("/")[0].split("=")[1].trim())/ba.alignment_length;
				ba.mismatches=ba.alignment_length-Integer.parseInt(tmp[i+1].split("/")[1].split("=")[1].trim());
				ba.strand=new char[2];
				ba.strand[0]=tmp[i+2].charAt(9);
				ba.strand[1]=tmp[i+2].charAt(10);
				ba.qstart=Integer.parseInt(tmp[i+4].split(" +")[1]);
				ba.tstart=Integer.parseInt(tmp[i+6].split(" +")[1]);
				break;
			}
		}
		for(int i=tmp.length-1;i>=0;i--){
			if(tmp[i].startsWith("Sbjct")){
				//read tail
				ba.tend=Integer.parseInt(tmp[i].split(" +")[3]);
				ba.qend=Integer.parseInt(tmp[i-2].split(" +")[3]);
				break;
			}
		}
		return ba;
	}
}
